//
//  TableViewController.m
//  KKRequestDemo
//
//  Created by Mac mini on 16/1/27.
//  Copyright © 2016年 JuniorCodingPerson. All rights reserved.
//

#import "TableViewController.h"

#import "KKQuestionTableViewCell.h"

@interface TableViewController () {
    
    NSArray *_titleArray;
}

@end

@implementation TableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.separatorColor = UITableViewCellSeparatorStyleNone;
    
    _titleArray = @[@"住院医师",@"主治医师",@"讲师",@"副主任医师",@"教授",@"主任医师",@"副教授",@"其他"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 10;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    NSInteger row = 1;
    
    switch (section) {
        case 3:
            row = 2;
            break;
        case 4:
            row = _titleArray.count;
            break;
            
        default:
            break;
    }
    
    return row;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    CGFloat rowHeight = 0.0;
    
    switch (section) {
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
        case 7:
            rowHeight = 30;
            break;
        case 5:
        case 6:
            rowHeight = 50;
            break;
            
        default:
            break;
    }
    
    return rowHeight;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    KKQuestionTableViewHeaderView *headerView = [[KKQuestionTableViewHeaderView alloc] initWithFrame: CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 60)];
    headerView.backgroundColor = [UIColor colorWithWhite: 0.85 alpha: 1.0];
    
    switch (section) {
        case 0:
        {
            [headerView kk_setTitle: @"医生姓名" andExplain: nil];
        }
            break;
        case 1:
        {
            [headerView kk_setTitle: @"出生年月" andExplain: nil];
        }
            break;
        case 2:
        {
            [headerView kk_setTitle: @"联系方式" andExplain: nil];
        }
            break;
        case 3:
        {
            [headerView kk_setTitle: @"性别" andExplain: nil];
        }
            break;
        case 4:
        {
            [headerView kk_setTitle: @"职称" andExplain: nil];
        }
            break;
        case 5:
        {
            [headerView kk_setTitle: @"个人说明" andExplain: @"简明地描述自己的职业生涯"];
        }
            break;
        case 6:
        {
            [headerView kk_setTitle: @"资质证件" andExplain: @"身份证、资格证、资质证书文件（jpg、jpeg、png）"];
        }
            break;
        case 7:
        {
            [headerView kk_setTitle: @"签名" andExplain: nil];
        }
            break;
            
        default:
            break;
    }
    
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSInteger section = indexPath.section;
    
    CGFloat rowHeight = 0.0;
    
    switch (section) {
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
            rowHeight = 40;
            break;
        case 5:
            rowHeight = 90;
            break;
        case 6:
            rowHeight = 120;
            break;
        case 7:
            rowHeight = CGRectGetWidth([[UIScreen mainScreen] bounds]) - 30;
            break;
            
        default:
            break;
    }
    
    return rowHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    
    NSInteger index = 0;
    
    switch (section) {
        case 0:
        case 1:
        case 2:
            index = 0;
            break;
        case 3:
        case 4:
            index = 2;
            break;
        case 5:
            index = 1;
            break;
        case 6:
            index = 3;
            break;
        case 7:
            index = 4;
            break;
            
        default:
            break;
    }
    
    KKQuestionTableViewCell *cell = [KKQuestionTableViewCell cellFromTableView: tableView reuseIdentifier: KKQuestionTableViewCellIdentifier index: index];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (section == 3) {
        cell.kk_optionLabel.text = row == 0 ? @"男":@"女";
    }
    else if (section == 4) {
        cell.kk_optionLabel.text = _titleArray[row];
        
        if (row == _titleArray.count - 1) {
            [cell kk_setOptionTextFieldHidden: false];
        }
    }
    
    return cell;
}


@end
